#pragma once

#include "workspace/IWorkspace.h"

class Workspace : public IWorkspace
{
	typedef std::map<String,sys::ObjectPtr> Documents;
	
public:
	BEGIN_DEFINE_CLASS(CLSID_Workspace)
		DEFINE_INTERFACE_ENTRY(IWorkspace)
	END_DEFINE_CLASS()

	Workspace();
	virtual ~Workspace();

	event_implement(DocumentEventHandler,DocumentCreating);
	event_implement(DocumentEventHandler,DocumentCreated);
	event_implement(DocumentOpenEventHandler,DocumentOpening);
	event_implement(DocumentEventHandler,DocumentOpened);
	event_implement(DocumentCloseEventHandler,DocumentClosed);
	event_implement(DocumentCloseEventHandler,DocumentClosing);

public:
	virtual vresult Create(const String& workpath);
	virtual void Close() ;
	virtual IDocument* NewDocument(documentCategory category,
																  pageTypesetCategory pageTypeset,
																  pageBindingCategory pageBinding,
																  uint32 pageCount,
																  real pageHeight,
																  real pageWidth,
																  real pageLeftMargin,
																  real pageTopMargin,
																  real pageRightMargin,
																  real pageBottonMargin);
	virtual IDocument* OpenDocument(const String& documentName) ;
	virtual vresult CloseDocument(const String& documentName);
	virtual IDocument* FindDocument(const String& documentName) const;
	virtual IDocument* GetDocument(uint32 index) const;
	virtual uint32 GetDocumentsCount() const;

	void UpdateDocumentName(const String& documentName);
	int GetNewDocumentCount() const;

private:
	Documents m_documents;
	String m_workpath;
};

AUTO_REGISTER_CLASSMAP_ENTRY(Workspace)